package com.syxd.controller;

import com.syxd.common.annotation.LogOperation;
import com.syxd.common.constant.Constant;
import com.syxd.common.entity.WebResult;
import com.syxd.common.utils.PageData;
import com.syxd.dto.SysSunCreditContactDto;
import com.syxd.dto.SysSunCreditDto;
import com.syxd.service.SysSunCreditContactService;
import com.syxd.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 业务经理对中间联系数据进行操作的接口
 */

@RestController
@RequestMapping("sys/sunCreditContact")
@Api(tags="阳光信贷临时数据操作")
public class SysSunCreditContactController {

    @Autowired
    SysSunCreditContactService sysCreditContactService;
    @Autowired
    SysUserService sysUserService;
    @PostMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = Constant.branchName, value = "支行名", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "operationType", value = "操作类型", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "processingStatus", value = "审批状态", paramType = "query", dataType = "int")
    })
    @LogOperation(apiType = "sysSunCreditContact", apiPath = "sys/SunCreditContact")
    @RequiresPermissions("approval:syssun:page")
    public WebResult<PageData<SysSunCreditContactDto>> page(@ApiIgnore @RequestBody Map<String, Object> params,HttpServletRequest request) {
        String branchName = (String) sysUserService.getInfoFromToken(request, "branchName").getData();
        if (branchName!=null){
            params.put("branchName",branchName);
        }
        PageData<SysSunCreditContactDto> page = sysCreditContactService.page(params);

        return new WebResult<PageData<SysSunCreditContactDto>>().ok(page);
    }
    @GetMapping("{id}")
    @LogOperation(apiType = "sysSunCreditContact", apiPath = "sys/SunCreditContact")
    @RequiresPermissions("public:sysjiang:page")
    public WebResult   query( @PathVariable("id") Long id ){


        return new WebResult().ok(sysCreditContactService.selectById(id));

    }
    @DeleteMapping("{id}")
    @ApiOperation("删除")
    @LogOperation(apiType = "sysSunCreditContact", apiPath = "sys/SunCreditContact")
    public WebResult delSunCreditContact(@PathVariable("id") Long id , HttpServletRequest request){



      return   sysCreditContactService.delSunCreditContact(id,request);


    }
    @PutMapping("update")
    @ApiOperation("修改")
    @LogOperation(apiType = "sysSunCreditContact", apiPath = "sys/CreditSunContact")
//    @RequiresPermissions("sys:sysrolepermission:update")
    public WebResult update(@RequestBody SysSunCreditDto dto, HttpServletRequest request) {
        //效验数据
        return  sysCreditContactService.update(dto,request);
    }
    @PutMapping
    @ApiOperation("新增")
   public WebResult put(@RequestBody SysSunCreditDto dto,HttpServletRequest request){

   return  sysCreditContactService.put(dto,request);

   }




}
